home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Mac Game Programming Gurus / TricksOfTheMacGameProgrammingGurus.iso / More Source / Libraries / SpriteEngine / SE Programmed Sprite / SpriteHanders.c < prev    next >
C/C++ Source or Header  |  1995-03-11  |  2KB  |  92 lines

  1. #include "SpriteTools.h"
  2.  
  3. // SpriteTools.h includes SpriteHandlers.h
  4.  
  5.  
  6. /*** Custom handlers - application dependent ***
  7.  
  8. Edit this as necessary. It should always include the following three routines:
  9.  
  10. MoveSprite: move the sprite
  11.  
  12. HitSprite: handle collisions between two sprites
  13.  
  14. InitSprites: Load all faces and create initial sprites
  15.  
  16. ***/
  17.  
  18.  
  19. typedef struct ProgramPart
  20. {
  21.     short    howLong;
  22.     short    dh;
  23.     short    dv;
  24. };
  25.  
  26. struct ProgramPart    program1[] =
  27. {
  28.     {60, 0,1},
  29.     {50, 1, 0},
  30.     {30, 0, -1},
  31.     {20, -1, 0},
  32.     {30, 0, -1},
  33.     {15, -2, 0},
  34.     {-1, -1, -1}
  35. };
  36.  
  37.  
  38. GrafPtr    firstFace, secondFace, thirdFace;
  39.  
  40.  
  41. void MoveSprite(SpritePtr theSprite)
  42. {
  43.     theSprite->position.h += program1[theSprite->currentInstruction].dh;
  44.     theSprite->position.v += program1[theSprite->currentInstruction].dv;
  45.     theSprite->timeOnCurrent++;
  46.     if (theSprite->timeOnCurrent >= program1[theSprite->currentInstruction].howLong)
  47.     {
  48.         theSprite->timeOnCurrent = 0;
  49.         theSprite->currentInstruction++;
  50.         if (program1[theSprite->currentInstruction].howLong < 0)
  51.             theSprite->currentInstruction = 0;
  52.     }
  53.     KeepOnScreen(theSprite);
  54. } /*MoveSprite*/
  55.  
  56. void HitSprite(SpritePtr theSprite, SpritePtr anotherSprite)
  57. {
  58. } /*HitSprite*/
  59.  
  60.  
  61. void InitSprites()
  62. {
  63.     SpritePtr    theSprite;
  64.  
  65. /*Load all pictures*/
  66.     firstFace = LoadFaceFromCicn(128);            /*cicn resource #128.*/
  67.     secondFace = LoadFaceFromCicn(129);            /*cicn resource #129.*/
  68.     thirdFace = LoadFaceFromCicn(130);            /*cicn resource #130.*/
  69.  
  70. /*Create sprites*/
  71.     theSprite = NewSprite();
  72.     theSprite->face = firstFace;
  73.     SetPt(&theSprite->position, 100, 100);
  74.     SetPt(&theSprite->speed, Rand(7)-3, Rand(7)-3);
  75.     theSprite->timeOnCurrent = 0;
  76.     theSprite->currentInstruction = 0;
  77.  
  78.     theSprite = NewSprite();
  79.     theSprite->face = secondFace;
  80.     SetPt(&theSprite->position, 50, 50);
  81.     SetPt(&theSprite->speed, Rand(7)-3, Rand(7)-3);
  82.     theSprite->timeOnCurrent = 0;
  83.     theSprite->currentInstruction = 0;
  84.  
  85.     theSprite = NewSprite();
  86.     theSprite->face = thirdFace;
  87.     SetPt(&theSprite->position, 150, 150);
  88.     SetPt(&theSprite->speed, Rand(7)-3, Rand(7)-3);
  89.     theSprite->timeOnCurrent = 0;
  90.     theSprite->currentInstruction = 0;
  91. } /*InitSprites*/
  92.